
/**
 * Date Modified: $Date: 2009-08-28 10:39:55 +1000 (Fri, 28 Aug 2009) $
 * Version: $Revision: 129 $
 * 
 * Copyright 2008 The Australian National University (ANU)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package org.ands.rifcs.example;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;

import javax.xml.parsers.ParserConfigurationException;


import org.ands.rifcs.base.*;

import org.xml.sax.SAXException;

public class Person
{
	private static RIFCS rifcs = null;

    public static void main(String[] args) throws RIFCSException, FileNotFoundException, SAXException, ParserConfigurationException, IOException
    {
        RIFCSWrapper mw = new RIFCSWrapper();
        rifcs = mw.getRIFCSObject();

        String custodians[][] = {
        /*key*/		{"john-wilson",
        /*family name*/ "Wilson",
        /*given name*/  "John",
        /*dataset relations*/  "http://www.biogrid.org.au/wps/wcm/connect/9e4eaf804eda2607b0a3b434012b7aaf/ATD_Alfred.pdf?MOD=AJPERES,http://www.biogrid.org.au/wps/wcm/connect/d4837c004eda28f2b563b534012b7aaf/CF_Alfred.pdf?MOD=AJPERES,http://www.biogrid.org.au/wps/wcm/connect/aaa260004eda32c9b5dfb534012b7aaf/Genetic.pdf?MOD=AJPERES" ,
        /*description*/  "John Wilson is a custodian of many datasets from Alfred Hospital" 
        		}
        };
        
        for(int i=0;i<custodians.length;i++){
        	RegistryObject r = rifcs.newRegistryObject();
            
            r.setKey(custodians[i][0]);
            r.setGroup("BioGrid");
            r.setOriginatingSource("https://services.ands.org.au/sandbox/orca");
            
            Party par = r.newParty();
            par.setType("person");
            
            Name n1 = par.newName();
            n1.setType("primary");
            NamePart np = n1.newNamePart();
            np.setType("family");
            np.setValue(custodians[i][1]);
            NamePart np2 = n1.newNamePart();
            np2.setType("given");
            np2.setValue(custodians[i][2]);
            n1.addNamePart(np);
            n1.addNamePart(np2);
            
            par.addName(n1);
            
            //dataset relation
            String datasetRelations[] = custodians[i][3].split(",");
            for(int m=0;m<datasetRelations.length;m++){
            	RelatedObject relObj1 = par.newRelatedObject();
                relObj1.setKey(datasetRelations[m]);
                relObj1.addRelation("isManagerOf", null, null, null);
                par.addRelatedObject(relObj1);
            }
            
            
            RelatedObject relObj3 = par.newRelatedObject();
            relObj3.setKey("www.biogrid.gov.au");
            relObj3.addRelation("isParticipantIn", null, "Policies on accessing data in BioGrid", null);
            par.addRelatedObject(relObj3);
             
            Description des = par.newDescription();
            des.setType("brief");
            des.setValue(custodians[i][4]);
            par.addDescription(des);
            
            r.addParty(par);
            rifcs.addRegistryObject(r);
        }
        
	    mw.validate();

	    FileOutputStream outputFile=null;
	    try{
	    	outputFile = new FileOutputStream("person.xml");
	    	
	    }
	    catch(IOException e1){
	    	System.out.println("Error writing to person2.xml");
	    }
	    
		//mw.write(System.out);
		mw.write(outputFile);
		System.out.println("Successfully written to XML file.");
    }
}